﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DriveBeamEditor.Controls.BeamNG.VehiclePartConfig;
using JBeamLibrary.VehicleParts;

namespace DriveBeamEditor.Controls.BeamNG.Controls
{
    public partial class PartSelectionControl : VehicleControl
    {
        #region Fields

        public event EventHandler<VehiclePart> SelectedVehiclePartChanged;
        public event EventHandler<VehiclePart> VehiclePartValidated;

        #endregion

        #region Properties

        public VehicleFile SelectedVehicleFile
        {
            get { return vehicleHierarchyControl.SelectedVehicleFile; }
        }

        public VehiclePart SelectedVehiclePart
        {
            get { return vehicleHierarchyControl.SelectedVehiclePart; }
            set { vehicleHierarchyControl.SelectedVehiclePart = value; }
        }

        #endregion

        #region CTORs

        public PartSelectionControl()
        {
            InitializeComponent();
        }

        #endregion

        #region Events

        private void vehicleHierarchyControl_SelectedVehiclePartChanged(object sender, EventArgs e)
        {
            if (SelectedVehiclePartChanged != null)
                SelectedVehiclePartChanged(this, vehicleHierarchyControl.SelectedVehiclePart);
        }

        private void vehicleHierarchyControl_VehiclePartValidated(object sender, JBeamLibrary.VehicleParts.VehiclePart e)
        {
            if (VehiclePartValidated != null)
                VehiclePartValidated(this, e);
        }

        #endregion

        #region Methods

        protected override void OnVehicleChanged()
        {
            vehicleHierarchyControl.Vehicle = Vehicle;
            base.OnVehicleChanged();
        }

        public void Reload()
        {
            vehicleHierarchyControl.Reload();
        }

        #endregion
    }
}
